<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>数据对比 </title>
    <script type="text/javascript" src="${request.contextPath}/skins/js/jquery.min.js"></script>
	<script type="text/javascript" src="${request.contextPath}/skins/js/jquery.md5.js"></script>
	<link href="${request.contextPath}/skins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
	<script src="${request.contextPath}/skins/bootstrap/js/bootstrap.min.js"></script>
	<script src="${request.contextPath}/skins/layer/layer.js"></script>
	<script src="${request.contextPath}/skins/js/clipboard/clipboard.js"></script>
	<script src="${request.contextPath}/skins/js//common.js"></script>
	<style type="text/css">
		.header_sign{
		}
		.title{
			color: brown;
   	 		font-size: 20px;
    		font-weight: 700;
			margin: 10px 0px;
		}
		.btn_div{
			margin-left: 40px;
		}
		.interpretation{
			margin-left: 40px;
		}
		.radio_suggest{
			height: 40px;
		    text-align: center;
		    border-width: 3px;
	  		border-style: solid;
		    border-radius: 5px;
		    color: white;
		    margin-right: 15px;
		    padding: 8px 16px;
		}
		.radio_suggest:hover {
			cursor:pointer;
		}
		.press{
			 border-color: blueviolet !important;
		}
		.pass{
			border-color: #55d98d;
			background-color: #55d98d;
		}
		.pass:hover{
			background-color: #65EA9D;
		}
		.mar_top{margin-top: 10px}
		.login_info{
			margin-bottom: 8px;
			padding: 5px;
			border: 3px #DDD solid;
			border-radius: 25px;
		}
		.login_name{
			margin-left: 20px;
			text-align: inherit;
			font-size: 24px;
			color: blueviolet;
		}
		.imput_text{
			text-align: end;
			font-size: 17px;
			font-weight: 600;
			margin-top: 6px;
		}
		.input_div{
			margin-top: 3px;
			width: 400px;
		}
	</style>
</head>
<body>
<div class="container-fluid">
<div class="row" >
<div class="col-xs-1" ></div>
<div class="col-xs-10" >
	<div class="col-xs-12">
		<h1  class="text-center col-xs-10">主页	</h1>
		<div class="col-xs-2" >
			<p class="text-right header_sign">by:authstr</p>
			<p class="text-right header_sign">versions:v0.5</p>
		</div>
	</div>
	<div>

		<form role="form" id="form1">
			<div class="col-xs-6">
				<div class="col-xs-12">

					<div class="col-xs-12 title">数据库连接(基准库): </div>
					<div class="col-xs-12 interpretation">创建的所有sql信息,都将把该库的数据视为正确数据进行创建.</div>
					<div class=" col-xs-12">
						<div class=" col-xs-12">
							<div class="col-xs-2  imput_text" >
								<span>连接地址:</span>
							</div>
							<div class="col-xs-10 ">
								<input type="text" class="input_div" name="standard_link_url"  value="" placeholder="连接地址请写完整url">
							</div>
						</div>
						<div class=" col-xs-12">
							<div class="col-xs-2  imput_text" >
								<span>用户名:</span>
							</div>
							<div class="col-xs-10 ">
								<input type="text" class="input_div" name="standard_username" value="" placeholder="用户名">
							</div>
						</div>

						<div class=" col-xs-12">
							<div class="col-xs-2  imput_text" >
								<span>密码:</span>
							</div>
							<div class="col-xs-10 ">
								<input type="text" class="input_div" name="standard_password" value="" placeholder="密码">
							</div>
						</div>

						<div class=" col-xs-12">
							<div class="col-xs-2  imput_text" >
								<span>查询sql:</span>
							</div>
							<div class="col-xs-10 ">
							<textarea type="text"  class="form-control input_div clipboard" name="newSql"  style="width:400px;height:120px;resize:none;"
									  placeholder="将使用该sql查询出的结果进行比较,查询结果字段建议写为*,系统将使用查询出的字段作为表的字段进行生成sql"></textarea>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="col-xs-6">
				<div class="col-xs-12">
					<div class="col-xs-12 title">数据库连接(更改库): </div>
					<!--<div class="col-xs-12 interpretation"></div>-->
					<div class=" col-xs-12">
						<div class=" col-xs-12">
							<div class="col-xs-2  imput_text" >
								<span>连接地址:</span>
							</div>
							<div class="col-xs-10 ">
								<input type="text" class="input_div" name="change_link_url"  value="" placeholder="连接地址请写完整url">
							</div>
						</div>
						<div class=" col-xs-12">
							<div class="col-xs-2  imput_text" >
								<span>用户名:</span>
							</div>
							<div class="col-xs-10 ">
								<input type="text" class="input_div" name="change_username" value="" placeholder="用户名">
							</div>
						</div>

						<div class=" col-xs-12">
							<div class="col-xs-2  imput_text" >
								<span>密码:</span>
							</div>
							<div class="col-xs-10 ">
								<input type="text" class="input_div" name="change_password" value="" placeholder="密码">
							</div>
						</div>

						<div class=" col-xs-12">
							<div class="col-xs-2  imput_text" >
								<span>查询sql:</span>
							</div>
							<div class="col-xs-10 ">
							<textarea type="text"  class="form-control input_div clipboard" name="oldSql" style="width:400px;height:120px;resize:none;"
									  placeholder="将使用该sql查询出的结果进行比较.查询结果字段建议写为*,系统将使用查询出的字段作为表的字段进行生成sql"></textarea>
							</div>
						</div>
					</div>
				</div>
			</div>


			<div class="col-xs-12">
				<div class="col-xs-12 title">基本设置: </div>
				<div class=" col-xs-12">
					<div class=" col-xs-12">
						<div class="col-xs-12  imput_text" style="text-align: inherit;" >
							<span>要操作的表名:</span>
						</div>
						<div class="col-xs-12 ">
							<div class="col-xs-1"></div>
							<input type="text" class="input_div col-xs-11" name="tableName"  value="" placeholder="如 `mydata`.`base_user` 建议写全称">
						</div>
					</div>
				</div>
				<div class=" col-xs-12">
					<div class=" col-xs-12">
						<div class="col-xs-12  imput_text" style="text-align: inherit;" >
							<span>要比较的列名:</span>
						</div>
						<div class="col-xs-12 ">
							<div class="col-xs-1"></div>
							<input type="text" class="input_div col-xs-11" name="uniqueColumn"  value="" placeholder="如用户表写username.如果多个列,以逗号分割">
						</div>
					</div>
					<div class="col-xs-12 interpretation">系统将以该列的比较结果判断是否创建插入还是删除等sql.</div>
					<div class="col-xs-12 interpretation">如指定比较username列,基准库有'张三',但更改库没有,就会创建一条插入语句.反之创建删除语句.如果usename一样才会尝试进行创建更新语句.</div>
					<div class="col-xs-12 interpretation">如果指定了多个列.多个列的值都一样才视为相等</div>
				</div>
				<div class=" col-xs-12">
					<div class=" col-xs-12">
						<div class="col-xs-12  imput_text" style="text-align: inherit;" >
							<span>创建更新语句时忽略的字段:</span>
						</div>
						<div class="col-xs-12 ">
							<div class="col-xs-1"></div>
							<input type="text" class="input_div col-xs-11" name="updateIgnoreColumn"  value="" placeholder="如 cjsj,whsj 多个列,以逗号分割">
						</div>
						<div class="col-xs-12 interpretation">在尝试创建更新语句时,如果这些列的值不一样,系统仍然会视为不用创建更新语句.</div>
					</div>
				</div>
				<div class=" col-xs-12">
					<div class=" col-xs-12">
						<div class="col-xs-12  imput_text" style="text-align: inherit;" >
							<span>是否生成注释:</span>
						</div>
						<div class="col-xs-12 ">
							<div class="col-xs-1"></div>
							<label><input type="radio" name="enableAddAnnotation" value="true" checked> 生成注释</label>
							<label><input type="radio" name="enableAddAnnotation" value="false"> 不生成注释</label>
						</div>
					</div>
				</div>
			</div>
			<div class="col-xs-12">
				<div class="col-xs-12 title">插入语句设置: </div>
				<div class="col-xs-12">
					<div class=" col-xs-12">
						<div class=" col-xs-12">
							<div class="col-xs-12  imput_text" style="text-align: inherit;" >
								<span>是否启用:</span>
							</div>
							<div class="col-xs-12 " style="margin-top: 10px;">
								<div class="col-xs-1"></div>
								<label><input type="radio" name="enableCreateInsert" value="true" checked> 启用</label>
								<label><input type="radio" name="enableCreateInsert" value="false"> 不启用</label>
							</div>
						</div>
					</div>
					<div class=" col-xs-12">
						<div class=" col-xs-12">
							<div class="col-xs-12  imput_text" style="text-align: inherit;" >
								<span>是否先创建删除语句(以id为限制条件):</span>
							</div>
							<div class="col-xs-12 " style="margin-top: 10px;">
								<div class="col-xs-1"></div>
								<label><input type="radio" name="enableDelectByIdOnInsert" value="true" > 创建</label>
								<label><input type="radio" name="enableDelectByIdOnInsert" value="false" checked> 不创建</label>
							</div>
						</div>
					</div>
					<div class=" col-xs-12">
						<div class=" col-xs-12">
							<div class="col-xs-12  imput_text" style="text-align: inherit;" >
								<span>是否先创建删除语句(以比较的列名为限制条件):</span>
							</div>
							<div class="col-xs-12 " style="margin-top: 10px;">
								<div class="col-xs-1"></div>
								<label><input type="radio" name="enableDelectByUniqueOnInsert" value="true" > 创建</label>
								<label><input type="radio" name="enableDelectByUniqueOnInsert" value="false" checked> 不创建</label>
							</div>
						</div>
					</div>
					<div class=" col-xs-12">
						<div class=" col-xs-12">
							<div class="col-xs-12  imput_text" style="text-align: inherit;" >
								<span>id是否使用生成的UUID,默认使用基准库的原id:</span>
							</div>
							<div class="col-xs-12 " style="margin-top: 10px;">
								<div class="col-xs-1"></div>
								<label><input type="radio" name="enableUserUUIDOnInsert" value="true" >UUID </label>
								<label><input type="radio" name="enableUserUUIDOnInsert" value="false" checked> 原id</label>
							</div>
						</div>
					</div>
				</div>
			</div>

			<div class="col-xs-12">
				<div class="col-xs-12 title">更新语句设置: </div>
				<div class="col-xs-12">
					<div class=" col-xs-12">
						<div class=" col-xs-12">
							<div class="col-xs-12  imput_text" style="text-align: inherit;" >
								<span>是否启用:</span>
							</div>
							<div class="col-xs-12 " style="margin-top: 10px;">
								<div class="col-xs-1"></div>
								<label><input type="radio" name="enableCreateUpdate" value="true" checked> 启用</label>
								<label><input type="radio" name="enableCreateUpdate" value="false"> 不启用</label>
							</div>
						</div>
					</div>
					<div class=" col-xs-12">
						<div class=" col-xs-12">
							<div class="col-xs-12  imput_text" style="text-align: inherit;" >
								<span>对于值一样的列数据,是否也写在更新语句中:</span>
							</div>
							<div class="col-xs-12 " style="margin-top: 10px;">
								<div class="col-xs-1"></div>
								<label><input type="radio" name="enableUpdateSameOnUpdate" value="true" > 添加</label>
								<label><input type="radio" name="enableUpdateSameOnUpdate" value="false" checked> 不添加</label>
							</div>
						</div>
					</div>
					<div class=" col-xs-12">
						<div class=" col-xs-12">
							<div class="col-xs-12  imput_text" style="text-align: inherit;" >
								<span>是否先创建删除语句(以id为限制条件):</span>
							</div>
							<div class="col-xs-12 " style="margin-top: 10px;">
								<div class="col-xs-1"></div>
								<label><input type="radio" name="enableDelectByIdOnUpdate" value="true" > 创建</label>
								<label><input type="radio" name="enableDelectByIdOnUpdate" value="false" checked> 不创建</label>
							</div>
						</div>
					</div>
					<div class=" col-xs-12">
						<div class=" col-xs-12">
							<div class="col-xs-12  imput_text" style="text-align: inherit;" >
								<span>是否先创建删除语句(以比较的列名为限制条件):</span>
							</div>
							<div class="col-xs-12 " style="margin-top: 10px;">
								<div class="col-xs-1"></div>
								<label><input type="radio" name="enableDelectByUniqueOnUpdate" value="true" > 创建</label>
								<label><input type="radio" name="enableDelectByUniqueOnUpdate" value="false" checked> 不创建</label>
							</div>
						</div>
					</div>
					<div class=" col-xs-12">
						<div class=" col-xs-12">
							<div class="col-xs-12  imput_text" style="text-align: inherit;" >
								<span>是否改为以插入语句来进行修改:</span>
							</div>
							<div class="col-xs-12 " style="margin-top: 10px;">
								<div class="col-xs-1"></div>
								<label><input type="radio" name="enableChangeInsertOnUpdate" value="true" > Insert语句</label>
								<label><input type="radio" name="enableChangeInsertOnUpdate" value="false" checked> Update语句</label>
							</div>
						</div>
					</div>
					<div class=" col-xs-12">
						<div class=" col-xs-12">
							<div class="col-xs-12  imput_text" style="text-align: inherit;" >
								<span>在插入语句,id是否使用生成的UUID,默认使用基准库的原id:</span>
							</div>
							<div class="col-xs-12 " style="margin-top: 10px;">
								<div class="col-xs-1"></div>
								<label><input type="radio" name="enableUserUUIDOnUpdate" value="true" > UUID</label>
								<label><input type="radio" name="enableUserUUIDOnUpdate" value="false" checked>原id </label>
							</div>
						</div>
					</div>
				</div>
			</div>

			<div class="col-xs-12">
				<div class="col-xs-12 title">删除语句设置: </div>
				<div class="col-xs-12">
					<div class=" col-xs-12">
						<div class=" col-xs-12">
							<div class="col-xs-12  imput_text" style="text-align: inherit;" >
								<span>是否启用:</span>
							</div>
							<div class="col-xs-12 " style="margin-top: 10px;">
								<div class="col-xs-1"></div>
								<label><input type="radio" name="enableCreateDelete" value="true" checked> 启用</label>
								<label><input type="radio" name="enableCreateDelete" value="false"> 不启用</label>
							</div>
						</div>
						<div class=" col-xs-12">
							<div class="col-xs-12  imput_text" style="text-align: inherit;" >
								<span>是否以唯一键作为限制条件进行创建(默认使用id):</span>
							</div>
							<div class="col-xs-12 " style="margin-top: 10px;">
								<div class="col-xs-1"></div>
								<label><input type="radio" name="enableUserUniqueDelete" value="true" > 使用比较列</label>
								<label><input type="radio" name="enableUserUniqueDelete" value="false" checked> 使用ID</label>
							</div>
						</div>
					</div>
				</div>
			</div>

			<div class="col-xs-12">

			</div>
		</form>
			<div class=" col-xs-12 btn_div">
				<button  class="btn hostlocal btn-info" onclick="Main.create()" ><i class="glyphicon glyphicon-plus"></i> <span>确定生成</span></button>
				<button  class="btn hostlocal" onclick="Main.settingToJson()" ></i> <span>当前设置转换为json</span></button>
				<button  class="btn  clipboard" data-clipboard-action="copy" data-clipboard-target="#sql_return"><i class="glyphicon glyphicon-file"></i> <span>复制生成文本</span></button>
				<button  class="btn " onclick="Main.getSettingForJson()" ><span>使用Json加载设置</span></button>
				<button  class="btn " onclick="Main.onlyDataSyncForJson()" ><span>使用Json直接执行</span></button>
				<button  class="btn " onclick="Main.manyDataSyncForJson()" ><span>使用Json数组批量执行</span></button>
			</div>

			<div class="col-xs-12">
				<div class="col-xs-12 title">生成结果: </div>
				<div class="col-xs-12">
					<div class=" col-xs-12">
						<div class="col-xs-1  imput_text" >
							<!--<span>查询sql:</span>-->
						</div>
						<div class="col-xs-11 ">
							<textarea type="text"  class="form-control input_div clipboard" id="sql_return"  style="width:100%;height:800px;resize:none;"
									  placeholder=""></textarea>
						</div>
					</div>
				</div>
			</div>
	</div>

</div>
</div>
</div>

</body>
<script type="text/javascript">
	var clipboard = new ClipboardJS('.clipboard');
	$("#isSyncLogin").val("${(isSyncLogin)!}");

	var openid=null
	var Main={
		create:function () {
			$.post("${request.contextPath}/onlyDataSync",$("#form1").serialize(),function(o){
				if(o.code==1){
					var sql_return="";

					var data=o.data
					$(data).each(function (index,elem) {
						sql_return=sql_return+"\r\n"+elem
					});
					$("#sql_return").val(sql_return);
					layer.msg(o.msg);
				}else{
					layer.alert(o.msg);
				}
			});
		},
		settingToJson:function () {
			$.post("${request.contextPath}/settingToJson",$("#form1").serialize(),function(o){
				if(o.code==1){
					var sql_return="";

					// var data=o.data
					// $(data).each(function (index,elem) {
					// 	sql_return=sql_return+"\r\n"+elem
					// });
					$("#sql_return").val(o.data);
					layer.msg(o.msg);
				}else{
					layer.alert(o.msg);
				}
			});
		},
		onlyDataSyncForJson:function () {
			$.post("${request.contextPath}/onlyDataSyncForJson",{json:$("#sql_return").val()},function(o){
				if(o.code==1){
					var setting=o.setting;
					for(var key in setting){
						if(setting[key]==true){
							setting[key]="true";
						}
						if(setting[key]==false){
							setting[key]="false";
						}
					}
					$("#form1").setFormValues(o.setting);
					var sql_return="";
					var data=o.data
					$(data).each(function (index,elem) {
						sql_return=sql_return+"\r\n"+elem
					});
					$("#sql_return").val(sql_return);
					layer.msg(o.msg);
				}else{
					layer.alert(o.msg);
				}
			});
		},
		manyDataSyncForJson:function () {
			$.post("${request.contextPath}/manyDataSyncForJson",{jsonArray:$("#sql_return").val()},function(o){
				if(o.code==1){
					var sql_return="";
					var data=o.data
					$(data).each(function (index,elem) {
						sql_return=sql_return+"\r\n"+elem
					});
					$("#sql_return").val(sql_return);
					layer.msg(o.msg);
				}else{
					layer.alert(o.msg);
				}
			});
		},
		getSettingForJson:function () {
			// $("#form1").setFormValues($("#sql_return").val());
			$.post("${request.contextPath}/getSettingForJson",{json:$("#sql_return").val()},function(o){
				if(o.code==1){
					var setting=o.setting;
					for(var key in setting){
						if(setting[key]==true){
							setting[key]="true";
						}
						if(setting[key]==false){
							setting[key]="false";
						}
					}
					$("#form1").setFormValues(o.setting);
					layer.msg(o.msg);
				}else{
					layer.alert(o.msg);
				}
			});
		}
	}
</script>
</html>